<template>
  <div>
    <header class="je-header">
      <div
        @tap="goBack($event)"
        class="back-btn mui-action-back">
        <i class="jeicon jeicon-angle-left" />
      </div>
      <div class="title">内容</div>
    </header>
    <div class="newsbulletin-pages-info">
      <div class="newsbulletin-top">
        <p class="newsbulletin-top-title">
          {{ listData.NOTICE_TITLE }}
        </p>
        <p class="newsbulletin-top-info">
          {{ listData.SY_CREATEUSERNAME }} 于 {{ listData.SY_CREATETIME }} 发布在{{ listData.NOTICE_NOTICETYPE_NAME }}
        </p>
        <div
          v-html="listData.NOTICE_CONTEXT"
          class="newsbulletin-context"
        />
      </div>
      <div class="newsbulletin-num">
        <span class="newsbulletin-ydl">
          <Icon
            type="jeicon-eye"
            size="xxxs"
            style="font-size:13px;color:#A9ABA9;"
          />
          {{ listData.NOTICE_YDL }}
        </span>
        <span
          @tap="doUpdateDzl(listData)"
          class="newsbulletin-ydl newsbulletin-dzl"
        >
          <Icon
            :style="{ color : !flag ? '#f7ba2a' : '#A9ABA9','font-size':'13px'}"
            :type="!flag ?'jeicon-thumbs-up':'jeicon-thumbs-up-o'"
            size="xxxs"
          />
          {{ listData.NOTICE_DZL }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { doUpdate } from '../../actions/action';
import Icon from '@/components/icon';

export default {
  name: 'NewsBulletinPagesInfo',
  components: {
    Icon,
  },
  data() {
    return {
      listData: '',
      flag: true,
    };
  },
  created() {
    /* const oldBack = mui.back;
    mui.back = () => {
      if (this.showBig) {
        this.showBig = false;
      } else {
        oldBack();
      }
      window.close();
    }; */
  },
  mounted() {
    //const currentWebview = plus.webview.currentWebview();

    // const oldBack = mui.back;
    // mui.back = () => {
    //   const parent = plus.webview.currentWebview().opener();
    //   mui.fire(parent, 'detailBack', {
    //   });
    //   oldBack();
    // };

    this.listData = this.$route.query.byIdData;
    // const parent = currentWebview.opener();
    // setTimeout(() => {
    //   // mui.fire(parent, 'clickInfoaddcount', {
    //   //   add: true,
    //   //   id: this.listData.JE_SYS_NOTICE_ID,
    //   // });
    // }, 1000);
    // 设置文本内的图片width=100%
    this.$nextTick(() => {
      const img = document.getElementsByTagName('img');
      const context = document.getElementsByClassName('newsbulletin-context')[0];
      const a = context.getElementsByTagName('a');
      for (let i = 0; i < img.length; i++) {
        // if (img[i].src.indexOf('/static/ux') != -1) {
        img[i].src = JE.getServerPath() + img[i].src.substr(7, img[i].src.length);
        // }
      }
      for (let i = 0; i < a.length; i++) {
        a[i].onclick = function () {
          plus.runtime.openURL(JE.getServerPath() + this.href.substr(7, this.href.length));
          return false;
        };
        // a[i].setAttribute('download', 'suanbanyun');
      }
    });
    // 判断该用户是否点赞
    const userCode = JE.getCurrentUser().userId;
    const ids = this.listData.NOTICE_DZUSERIDS.split(',');
    if (ids) {
      ids.forEach((id) => {
        if (id == userCode) {
          this.flag = false;
        }
      });
    }
  },
  methods: {
    // 点赞方法
    doUpdateDzl(data) {
      if (this.flag) {
        const userCode = JE.getCurrentUser().userId;
        const NOTICE_DZUSERIDS = `${data.NOTICE_DZUSERIDS},${userCode}`;
        const NOTICE_DZL = parseInt(data.NOTICE_DZL) + 1;
        doUpdate({
          tableCode: 'JE_SYS_NOTICE',
          NOTICE_DZUSERIDS,
          NOTICE_DZL,
          JE_SYS_NOTICE_ID: data.JE_SYS_NOTICE_ID,
        }).then((data) => {
          if (data.success) {
            this.listData.NOTICE_DZL = data.obj.NOTICE_DZL;
            this.flag = false;
            //  告诉上级页面 已点赞  状态重置逻辑
            const parent = plus.webview.currentWebview().opener();
            mui.fire(parent, 'doUpdateDzl', {
              id: data.obj.JE_SYS_NOTICE_ID,
              NOTICE_DZL: data.obj.NOTICE_DZL,
              NOTICE_DZUSERIDS: data.obj.NOTICE_DZUSERIDS,
            });
            mui.toast('点赞成功!');
          } else {
            mui.toast('点赞失败!');
          }
        });
      }
    },
  },
};
</script>
<style lang="less" scoped>
@import "~@/theme/index.less";
.newsbulletin-pages-info {
  position: absolute;
  top: unit(45 * @hd, px);
  right: 0;
  bottom: 0;
  left: 0;
  .newsbulletin-top {
    padding: 16 * @hd;
    padding-bottom :60 * @hd;
  }
  .newsbulletin-top-title {
    font-size: 20 * @hd;
    color: #3f3f3f;
    font-weight: bold;
    line-height: 24 * @hd;
  }
  .newsbulletin-top-info {
    //line-height: 34 * @hd;
    font-size: 15 * @hd;
    color: #a9aba9;
    margin:10 * @hd 0;
  }
  .newsbulletin-num {
    padding: 16 * @hd;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    border-top: #F5F5F5 1 * @hd solid;
    background:#FFFFFF;
    text-align: right;
  }
  .newsbulletin-ydl {
    /*border: 1.5px solid #F5F5F5;
    border-radius: 22 * @hd;
    width:100 * @hd;
    height: 44 * @hd;
    padding: 3 * @hd 10 * @hd;
    color: #a9aba9;
    font-size: 16 * @hd;*/
    border: 1.5px solid #F5F5F5;
    border-radius: 22 * @hd;
    display: inline-block;
    width: 80  * @hd;
    height: 30  * @hd;
    text-align: center;
    margin: 0 auto;
    padding: 2.5  * @hd;
    color: #A9ABA9;;
    &.newsbulletin-dzl {
      margin-left: 15 * @hd;
    }
  }
}
</style>
<style lang="less">
@import "~@/theme/index.less";
html,
body {
  background:#FFFFFF;
}
.newsbulletin-context{
  img {
    width: auto;
    max-width: 100%;
  }
  p{
  line-height : normal !important;
}
table{
  width: 100% !important;
}
}
</style>
